package com.park.manage.service.manage.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.park.comm.ResultEnum;
import com.park.dao.mapper.manage.MerManageLoginMapper;
import com.park.entity.manage.ParkAdminInfo;
import com.park.exception.CommException;
import com.park.manage.service.manage.MerManageLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Administrator
 * @title: MerManageLoginServiceImpl
 * @projectName park
 * @description: merManageLoginService
 * @date 2020/5/420:05
 */
@Service(value = "merManageLoginService")
public class MerManageLoginServiceImpl implements MerManageLoginService {

    @Autowired
    private MerManageLoginMapper merManageLoginMapper;

    /**
     * 管理台登录
     * @param parkAdminInfo
     */
    public void login(ParkAdminInfo parkAdminInfo) {
        String adminName = parkAdminInfo.getAdminName();
        String adminPassword = parkAdminInfo.getAdminPassword();
        ParkAdminInfo parkAdminInfoData = merManageLoginMapper.getAdminInfoByAdminName(adminName);
        if(ObjectUtil.isEmpty(parkAdminInfoData)){
            throw new CommException(ResultEnum.ADMIN_NAME_ERROR);
        }
        String adminPasswordMd5 = parkAdminInfoData.getAdminPassword();
        if(!StrUtil.equals(adminPasswordMd5,SecureUtil.md5(adminPassword))){
            throw new CommException(ResultEnum.ADMIN_PASSWORD_ERROR);
        }
    }
}
